//
//  AppDelegate.swift
//  新浪微博
//
//  Created by 名品导购网MPLife.com on 2017/11/20.
//  Copyright © 2017年 sweet. All rights reserved.
//

import UIKit
import SVProgressHUD
import AFNetworking
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        //取得用户授权显示通知 上方的提示条 声音 bagenumber
        //.badge .alert .sound 数字 提示 声音
        //设置应用程序额外设置
        setUpAdditions()
      
        window = UIWindow()
        window?.backgroundColor = UIColor.white
        window?.rootViewController = WBMainViewController()
        if #available(iOS 11.0, *){
            UIScrollView .appearance() .contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentBehavior.never
        }
        window?.makeKeyAndVisible()
        loadAppInfo()
        return true
    }


}
//设置应用额外信息
extension AppDelegate{
    //
    private func setUpAdditions(){
        //设置svprogressHuud 最小解除时间
        SVProgressHUD .setMinimumDismissTimeInterval(2)
        //设置网路加载指示器
        AFNetworkActivityIndicatorManager .shared() .isEnabled = true
        //设置用户授权显示通知
        let notifysetting = UIUserNotificationSettings(types:.badge, categories: nil)
    UIApplication .shared .registerUserNotificationSettings(notifysetting)
    }
}
//从服务器加载应用程序信息
extension AppDelegate {
    private func loadAppInfo(){
        DispatchQueue .global() .async {
            let url = Bundle .main .url(forResource: "main.json", withExtension: nil)
            let data = NSData(contentsOf: url!)
            let docDir = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
            let jsonPath = (docDir as NSString) .appendingPathComponent("main.json")
            //保存在沙盒，等待下一次程序启动
            data?.write(toFile: jsonPath, atomically: true)
//            print("应用加载完毕\(jsonPath)")
        }
        
    }
}

